

#include "GameEditor.h"
#include "ProjectDoc.h"


ProjectDoc::ProjectDoc(QObject *parent /* = 0 */)
	: QDocument(parent)
	, mInfo()
{

}

ProjectDoc::~ProjectDoc()
{

}

bool ProjectDoc::onCreateDocument()
{
	QString val(GAME_EDITOR_APP_NAME);
	QVariant var(val);
	mInfo.insert("Application", var);
	val = GAME_EDITOR_VERSION_STR;
	var = qVariantFromValue(val);
	mInfo.insert("Version", var);

	QFile *file = fileObject();

	const QString &path  = location();
	bool result = mInfo.archive(file);

	if (result)
	{
		QString dirPath = path + "Output";
		QDir dir;
		dir.mkpath(dirPath);
	}

	return result;
}

bool ProjectDoc::onOpenDocument()
{
	QFile *file = fileObject();

	return mInfo.unarchive(file);
}

bool ProjectDoc::onSaveDocument()
{
	QFile *file = fileObject();

	return mInfo.archive(file);
}

void ProjectDoc::onCloseDocument()
{
	mInfo.clear();
}

